home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Ebooks / Thinking in C++ V2 / C20 / StreamTokenizer.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-25  |  789 b   |  29 lines

  1. //: C20:StreamTokenizer.h
  2. // From Thinking in C++, 2nd Edition
  3. // Available at http://www.BruceEckel.com
  4. // (c) Bruce Eckel 1999
  5. // Copyright notice in Copyright.txt
  6. // C++ Replacement for Standard C strtok()
  7. #ifndef STREAMTOKENIZER_H
  8. #define STREAMTOKENIZER_H
  9. #include <string>
  10. #include <iostream>
  11. #include <iterator>
  12.   
  13. class StreamTokenizer {
  14.   typedef std::istreambuf_iterator<char> It;
  15.   It p, end;
  16.   std::string delimiters;
  17.   bool isDelimiter(char c) {
  18.     return 
  19.       delimiters.find(c) != std::string::npos;
  20.   }
  21. public:
  22.   StreamTokenizer(std::istream& is, 
  23.     std::string delim = " \t\n;()\"<>:{}[]+-=&*#"
  24.     ".,/\\~!0123456789") : p(is), end(It()),
  25.     delimiters(delim) {}
  26.   std::string next(); // Get next token
  27. };
  28. #endif STREAMTOKENIZER_H ///:~
  29.